/*
 * Poyke Framework
 * Copyright (C) 2010 Poyke <http://code.google.com/p/poyke/>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#ifndef POYKE_CORE_LOADER_H
#define POYKE_CORE_LOADER_H

typedef void (*CORE_PROTO_INIT)(bool just_crashed);
typedef bool (*CORE_PROTO_SAVE)();

enum LOAD_CORE_RESULTS
{
	LOAD_CORE_SUCCESS,					// Loaded core successfully
	LOAD_CORE_FAIL_NO_DLL,				// Unable to find Core.dll
	LOAD_CORE_FAIL_NO_ENTRY,			// Unable to find CORE_PROTO_INIT function
	LOAD_CORE_FAIL_NO_SAVESTATE,		// Unable to find CORE_PROTO_SAVE function
	LOAD_CORE_FAIL_UNKNOWN				// Another error occurred
};

enum UNLOAD_CORE_RESULTS
{
	UNLOAD_CORE_SUCCESS,				// Unloaded core successfully
	UNLOAD_CORE_FAIL_IN_USE,			// Unable to halt threads
	UNLOAD_CORE_FAIL_UNKNOWN			// Another error occurred
};

class CoreLoader
{
public:
	static CoreLoader *GetInstance();
	LOAD_CORE_RESULTS LoadCore(bool just_crashed = false);
	UNLOAD_CORE_RESULTS UnloadCore(bool force = false);
	void SignalSaveState();

private:
	static CoreLoader *_instance;

	CoreLoader();
	~CoreLoader();
	CORE _hCore;
	CORE_PROTO_INIT _InitCore;
	CORE_PROTO_SAVE _SaveState;

};

#define sCoreLoader CoreLoader::GetInstance()

#endif
